/**
 * Created with JetBrains PhpStorm.
 * User: jiangshuguang
 * Date: 14-7-25
 * Time: 下午12:41
 * To change this template use File | Settings | File Templates.
 */
var createUi = require("iphone:widget/ui/base/base.js").createUi;
var DConfirm = P.createUi({
    _data:{
        title:"确定框",
        content:"",
        width:400,
        onConfirm:function(){},
        onCancel:function(){}
    },
    _create:function(){
        var me = this,
            title = this.data("title"),
            content = this.data("content"),
            $root =
            $('' +
                '<div title="'+title+'">' +
                '<div class="content" style="color:#54af1e">' + content + '</div>' +
                '</div>' ).dialog({
                    modal: true,
                    autoOpen:false,
                    width:me.data('width'),
                    buttons: {
                        "确定": function() {
                            var _me = this;
                            me.trigger("confirm",function(){
                                $(_me).dialog('close');
                            });
                        },
                        "取消":function(){
                            me.trigger("cancel");
                            $(this).dialog('close');
                        }
                    }
                });
        this.data({
            $root:$root
        })
    },
    _init:function(){

    },

    show:function(content){
        var $root = this.data("$root");
        !!content && $root.find(".content").html(content);
        $root.dialog('open');
    },

    hide:function(){
        this.data("$root").dialog('close');
    }
});

$.extend(exports,{
    DConfirm:DConfirm,
    dConfirm:function(params){
        return new DConfirm(params);
    }
});